package ru.cod.rs.main.managers;

import static ru.cod.rs.main.enums.Side.ALLY;
import static ru.cod.rs.main.enums.Side.ENEMY;

import java.util.ArrayList;
import java.util.List;

import ru.cod.rs.main.types.LevelPreferences;
import ru.cod.rs.main.units.Unit;
import ru.cod.rs.main.units.entities.FireIceMan;
import ru.cod.rs.main.units.entities.NakedMan;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.SurfaceView;

public class GameManager extends DrawManager {
	protected Context context;
	protected Integer ground;
	protected Integer border;

	public GameManager(Context cntx, SurfaceView v) {
		super(v);
		context = cntx;
		units = new ArrayList<Unit>();

		border = view.getWidth();
		ground = view.getHeight();

		LevelPreferences prefs = new LevelPreferences(view, border, ground);
		addUnits(prefs);
	}

	// /////////////////////////////////////////
	private List<Unit> units;

	// ////////////////////////////////////////

	@Override
	protected void draw(Canvas canvas) {
		update();
		render(canvas);
	}

	private void update() {
		for (Unit u : units) {
			u.update();
		}
	}

	private void render(Canvas canvas) {
		renderBG(canvas);
		for (Unit u : units) {
			u.render(canvas);
		}
	}

	private void renderBG(Canvas canvas) {
		canvas.drawColor(Color.BLACK);
	}

	public void addUnits(LevelPreferences prefs) {
		units.add(new NakedMan(prefs, ALLY));
		units.add(new FireIceMan(prefs, ENEMY));
	}
}
